public class StudentTest {
    public static void main(String[] args) {
        Student[] arr = new Student[3];
        Student s1 = new Student(12, "zhansgan", 001);
        Student s2 = new Student(13, "lisi", 002);
        Student s3 = new Student(14, "wangwu", 003);
        arr[0] = s1;
        arr[1] = s2;
        arr[2] = s3;
        //通过id删除学生信息
        //存在删除,不存在删除失败

        int index = getIndex(arr,002);
        System.out.println(index);
        if(index>=0){
            arr[index] = null;
            printArr(arr);
        }else{
            System.out.println("删除失败");
        }
    }

    public static int getIndex(Student[] arr,int id) {
        for (int i = 0; i < arr.length; i++) {
           Student stu =  arr[i];
           if(stu!=null){
               int sid = stu.getId();
               if(sid == id){
                   return  i;
               }
           }

        }
        return  -1;
    }

    public static void printArr(Student[] arr) {
        for (int i = 0; i < arr.length; i++) {
            Student s = arr[i];
            if (arr[i] != null) {
                System.out.println(s.getId() + ", " + s.getAge() + ", " + s.getName());
            }
        }
    }
}
